home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 008a / fgdemo10.zip / MISC.C < prev    next >
Text File  |  1991-10-02  |  14KB  |  546 lines

  1. /**********************************************************************\
  2. *                                                                      *
  3. *  misc.c -- sound, music, editor, etc. -- things on the MISC menu     *
  4. *                                                                      *
  5. \**********************************************************************/
  6.  
  7. #include "defs.h"
  8.  
  9. /**********************************************************************\
  10. *                                                                      *
  11. *  do_editor -- call the editor                                        *
  12. *                                                                      *
  13. \**********************************************************************/
  14.  
  15. do_editor()
  16. {
  17.    char *array;
  18.    int array_len;
  19.  
  20.    /* allocate a string to pass to the editor function */
  21.  
  22.    array = calloc(10000,sizeof(char));
  23.    if (array == NULL)
  24.       return(ERR);
  25.  
  26.    /* define a black background */
  27.  
  28.    background = 0;
  29.  
  30.    /* clear the screen */
  31.  
  32.    fg_mousevis(OFF);
  33.    fg_restore(0,xlimit,menu_bottom,ylimit);
  34.  
  35.    /* draw the box */
  36.  
  37.    fg_setcolor(0);
  38.    fg_rect(144,487,50,180);
  39.    fg_setcolor(15);
  40.    fg_rect(144,487,181,195);
  41.    fg_setcolor(0);
  42.    fg_rect(144,487,196,196);
  43.    center_pstring("Press F1 for help, Esc to exit",150,490,195);
  44.  
  45.    /* call the editor function */
  46.  
  47.    fg_setcolor(15);
  48.    editor(array,148,485,53,180,20,&array_len);
  49.  
  50.    /* redraw the screen */
  51.  
  52.    draw_screen();
  53.    fg_restore(0,xlimit,0,ylimit);
  54.    highlight_option(4);
  55.    fg_mousevis(ON);
  56.  
  57.    /*******************************************************************
  58.  
  59.    This editor is included for demonstration purposes only, and does
  60.    not write anything out to a file.  If you were going to write the
  61.    text to a text file, you would probably want to do something like
  62.    this:
  63.  
  64.    index = 0;
  65.    for (i = 0; i < 20; i++)
  66.    {
  67.       nchar = strlen(&array[index]);
  68.       fprintf(stream,"%s\n",&ver_array[index]);
  69.       index+=nchar;
  70.       index+=2;
  71.  
  72.       if (index >= array_len)
  73.          break;
  74.    }
  75.  
  76.    Notice that the array is a collection of null terminated strings.
  77.    Be sure to free the array when you are done.
  78.  
  79.    *******************************************************************/
  80.  
  81.    free(array);
  82.    redraw = TRUE;
  83.  
  84.    return(OK);
  85. }
  86.  
  87. /**********************************************************************\
  88. *                                                                      *
  89. *  do_histogram -- create a histogram                                  *
  90. *                                                                      *
  91. \**********************************************************************/
  92.  
  93. do_histogram()
  94. {
  95.    register int i;
  96.    int x1,x2,y1,y2;
  97.    static char label[] = "Productivity";
  98.    static char title[] = "See profits soar with Fastgraph!";
  99.  
  100.    static int x[] = {130, 180, 230, 280, 330, 380, 430, 480};
  101.    static int y[] = {290, 275, 270, 265, 200, 170, 130, 100};
  102.  
  103.    /* clear the bottom of the screen */
  104.  
  105.    fg_mousevis(OFF);
  106.    fg_restore(0,xlimit,menu_bottom,ylimit);
  107.  
  108.    fg_setpage(visual);
  109.    fg_setcolor(0);
  110.  
  111.    y1 = scale(100);
  112.    y2 = scale(300);
  113.  
  114.    /* axes */
  115.  
  116.    fg_rect(120,520,y2,y2);
  117.    fg_rect(120,120,y1,y2);
  118.  
  119.    for (i = 100; i < 300; i+=20)
  120.    {
  121.       y1 = scale(i);
  122.       fg_rect(120,126,y1,y1);
  123.    }
  124.  
  125.    /* boxes */
  126.  
  127.    for (i = 0; i < 8; i++)
  128.    {
  129.       x1 = x[i];
  130.       x2 = x1 + 30;
  131.       y1 = scale(y[i]);
  132.  
  133.       fg_setcolor(11);
  134.       fg_rect(x1,x2,y1,y2);
  135.  
  136.       fg_setcolor(0);
  137.       draw_box(x1,x2,y1,y2);
  138.    }
  139.  
  140.    /* label the x axis */
  141.  
  142.    x1 = 320 - length_pstring(label)/2 - 2;
  143.    x2 = 320 + length_pstring(label)/2 + 2;
  144.    y2 = scale(320);
  145.    y1 = y2 - ptsize - 1;
  146.    if (mode06 || mode11)
  147.    {
  148.       fg_setcolor(15);
  149.       fg_rect(x1,x2,y1,y2);
  150.    }
  151.    fg_setcolor(0);
  152.    center_pstring(label,x1,x2,y2);
  153.  
  154.    /* Profits soar with Fastgraph */
  155.  
  156.    x1 = 320 - length_pstring(title)/2 - 2;
  157.    x2 = 320 + length_pstring(title)/2 + 2;
  158.    y2 = scale(90);
  159.    y1 = y2 - ptsize - 1;
  160.    if (mode06 || mode11)
  161.    {
  162.       fg_setcolor(15);
  163.       fg_rect(x1,x2,y1,y2);
  164.    }
  165.    fg_setcolor(0);
  166.    center_pstring(title,x1,x2,y2);
  167.  
  168.    /* wait for a keystroke or mouse button */
  169.  
  170.    fg_mousevis(ON);
  171.    wait_for_keystroke();
  172.  
  173.    /* restore the screen and return to the menu */
  174.  
  175.    fg_restore(0,xlimit,menu_bottom,ylimit);
  176.    redraw = TRUE;
  177.  
  178.    return(OK);
  179. }
  180.  
  181. /**********************************************************************\
  182. *                                                                      *
  183. *  do_joystick -- demo some joystick functions                         *
  184. *                                                                      *
  185. \**********************************************************************/
  186.  
  187. do_joystick()
  188. {
  189.    static char *string1[] = {
  190.    "Joystick",
  191.    "Joysticks found on Port 1 and Port 2."
  192.    };
  193.  
  194.    static char *string2[] = {
  195.    "Joystick",
  196.    "Joystick found on Port 1."
  197.    };
  198.  
  199.    static char *string3[] = {
  200.    "Joystick",
  201.    "Joystick found on Port 2."
  202.    };
  203.  
  204.    static char *string4[] = {
  205.    "Joystick",
  206.    "Joystick not found."
  207.    };
  208.  
  209.    static int joy1_x[] = {140,200,260,140,200,260,140,200,260};
  210.    static int joy2_x[] = {360,420,480,360,420,480,360,420,480};
  211.    static int joy_y[] =  {110,110,110,140,140,140,170,170,170};
  212.  
  213.    unsigned char key,aux;
  214.    int x,y;
  215.    int count,mousex,mousey;
  216.    int pos1,pos2,new_pos1,new_pos2;
  217.    int joystick[2];
  218.  
  219.    /* initialize joysticks, if possible */
  220.  
  221.    if (fg_initjoy(1) == 0)
  222.       joystick[0] = TRUE;
  223.    else
  224.       joystick[0] = FALSE;
  225.  
  226.    if (fg_initjoy(2) == 0)
  227.       joystick[1] = TRUE;
  228.    else
  229.       joystick[1] = FALSE;
  230.  
  231.    fg_mousevis(OFF);
  232.    fg_restore(0,xlimit,menu_bottom,ylimit);
  233.  
  234.    /* report status of joysticks */
  235.  
  236.    if (joystick[0] && joystick[1])
  237.       info_window(120,520,45,string1,2);
  238.    else if (joystick[0])
  239.       info_window(120,520,45,string2,2);
  240.    else if (joystick[1])
  241.       info_window(120,520,45,string3,2);
  242.    else
  243.       info_window(120,520,45,string4,2);
  244.  
  245.    /* draw a grid to illustrate joystick positions */
  246.  
  247.    fg_mousevis(OFF);
  248.    if (joystick[0])
  249.    {
  250.       fg_setcolor(15);
  251.       fg_rect(120,300,100,190);
  252.       fg_setcolor(0);
  253.       draw_box(120,300,100,190);
  254.       draw_box(180,240,100,190);
  255.       draw_box(120,300,130,160);
  256.    }
  257.  
  258.    if (joystick[1])
  259.    {
  260.       fg_setcolor(15);
  261.       fg_rect(340,520,100,190);
  262.       fg_setcolor(0);
  263.       draw_box(340,520,100,190);
  264.       draw_box(400,460,100,190);
  265.       draw_box(340,520,130,160);
  266.    }
  267.  
  268.    pos1 = 4; new_pos1 = pos1;
  269.    pos2 = 4; new_pos2 = pos2;
  270.  
  271.    /* draw red boxes to represent joystick straight up position */
  272.  
  273.    fg_setcolor(4);
  274.    if (joystick[0])
  275.    {
  276.       x = joy1_x[pos1];
  277.       y = joy_y[pos1];
  278.       fg_rect(x,x+20,y,y+10);
  279.    }
  280.    if (joystick[1])
  281.    {
  282.       x = joy2_x[pos2];
  283.       y = joy_y[pos2];
  284.       fg_rect(x,x+20,y,y+10);
  285.    }
  286.  
  287.    fg_mousevis(ON);
  288.    while (TRUE)
  289.    {
  290.       fg_waitfor(3);
  291.  
  292.       /* handle first joystick */
  293.  
  294.       if (joystick[0])
  295.       {
  296.          fg_intjoy(1,&key,&aux);
  297.          if (key == CR)
  298.             break;
  299.          if (aux == 0)
  300.             new_pos1 = 4;
  301.          else if (aux >= 71 && aux <= 73)
  302.             new_pos1 = aux - 71;
  303.          else if (aux >= 75 && aux <= 77)
  304.             new_pos1 = aux - 72;
  305.          else if (aux >= 79 && aux <= 81)
  306.             new_pos1 = aux - 73;
  307.  
  308.          if (new_pos1 != pos1)
  309.          {
  310.             fg_setcolor(15);
  311.             x = joy1_x[pos1];
  312.             y = joy_y[pos1];
  313.             fg_mousevis(OFF);
  314.             fg_rect(x,x+20,y,y+10);
  315.  
  316.             pos1 = new_pos1;
  317.             fg_setcolor(4);
  318.             x = joy1_x[pos1];
  319.             y = joy_y[pos1];
  320.             fg_rect(x,x+20,y,y+10);
  321.             fg_mousevis(ON);
  322.          }
  323.       }
  324.  
  325.       /* handle second joystick */
  326.  
  327.       if (joystick[1])
  328.       {
  329.          fg_intjoy(2,&key,&aux);
  330.          if (key == CR)
  331.             break;
  332.          if (aux == 0)
  333.             new_pos2 = 4;
  334.          else if (aux >= 71 && aux <= 73)
  335.             new_pos2 = aux - 71;
  336.          else if (aux >= 75 && aux <= 77)
  337.             new_pos2 = aux - 72;
  338.          else if (aux >= 79 && aux <= 81)
  339.             new_pos2 = aux - 73;
  340.  
  341.          if (new_pos2 != pos2)
  342.          {
  343.             fg_setcolor(15);
  344.             x = joy2_x[pos2];
  345.             y = joy_y[pos2];
  346.             fg_mousevis(OFF);
  347.             fg_rect(x,x+20,y,y+10);
  348.  
  349.             pos2 = new_pos2;
  350.             fg_setcolor(4);
  351.             x = joy2_x[pos2];
  352.             y = joy_y[pos2];
  353.             fg_rect(x,x+20,y,y+10);
  354.             fg_mousevis(ON);
  355.          }
  356.       }
  357.  
  358.       /* exit loop if key or mouse button pressed */
  359.  
  360.       fg_intkey(&key,&aux);
  361.       if (key+aux > 0)
  362.          break;
  363.  
  364.       fg_mousebut(1,&count,&mousex,&mousey);
  365.       if (count > 0)
  366.          break;
  367.    }
  368.  
  369.    /* restore the screen and return to the menu */
  370.  
  371.    fg_mousevis(OFF);
  372.    fg_restore(0,xlimit,menu_bottom,ylimit);
  373.  
  374.    redraw = TRUE;
  375.    return(OK);
  376. }
  377.  
  378. /**********************************************************************\
  379. *                                                                      *
  380. *  do_mouse -- change the mouse cursor                                 *
  381. *                                                                      *
  382. \**********************************************************************/
  383.  
  384. do_mouse()
  385. {
  386.    /* I used the MCD program from Rimrock Software to generate
  387.       the mouse cursor array. */
  388.  
  389.    static int fgcursor[] = {
  390.     0x0083,0x0001,0x0000,0x0018,0x0e18,0x0018,0x0018,0x001f,
  391.     0x0000,0x0e00,0x0e00,0x0e10,0x0e10,0x0e00,0x0e00,0x0f00,
  392.     0x0000,0x7e3c,0x7e66,0x60c2,0x60c2,0x60c2,0x7ec0,0x7ec0,
  393.     0x60c0,0x60ce,0x60ce,0x60c6,0x60c6,0x60e6,0x607e,0x0000};
  394.  
  395.    static char *string[] = {
  396.    "Mouse",
  397.    "Fastgraph has routines to poll the mouse,",
  398.    "move the mouse, turn the cursor off and on,",
  399.    "and even change the shape of the mouse cursor.",
  400.    };
  401.  
  402.    static char *string1[] = {
  403.    "Mouse",
  404.    "Mouse Driver not found.",
  405.    };
  406.  
  407.    int lastx, lasty, buttons;
  408.  
  409.    /* clear the screen and display the info window */
  410.  
  411.    fg_mousevis(OFF);
  412.    fg_restore(0,xlimit,menu_bottom,ylimit);
  413.  
  414.    if (mouse)
  415.       info_window(120,520,60,string,4);
  416.    else
  417.       info_window(120,520,60,string1,2);
  418.  
  419.    /* if the mouse is present, change the mouse cursor */
  420.  
  421.    if (mouse)
  422.       fg_mouseptr(fgcursor,0,0);
  423.  
  424.    /* wait for a keystroke or mouse button */
  425.  
  426.    fg_mousevis(ON);
  427.    wait_for_keystroke();
  428.  
  429.    fg_mousevis(OFF);
  430.  
  431.    /* restore the default cursor */
  432.  
  433.    if (mouse)
  434.    {
  435.       fg_mousepos(&lastx,&lasty,&buttons);  /* get current position */
  436.       fg_mouseini();                        /* restore default cursor */
  437.       fg_mousemov(lastx,lasty);             /* move to last position */
  438.    }
  439.  
  440.    /* restore the screen and return to the menu */
  441.  
  442.    fg_restore(0,xlimit,menu_bottom,ylimit);
  443.    redraw = TRUE;
  444.  
  445.    return(OK);
  446. }
  447.  
  448. /**********************************************************************\
  449. *                                                                      *
  450. *  do_music -- play "Stranger in Paradise"                             *
  451. *                                                                      *
  452. \**********************************************************************/
  453.  
  454. do_music()
  455. {
  456.    unsigned char key,aux;
  457.    int count,lastx,lasty;
  458.  
  459.    static char music[] =
  460.    "T140O4L4GGO+L2DL8CDO-L4A#L8AGAA#L2O+C"
  461.    "L4DO-AL8GFL4DDL2GL4AGL8FE"
  462.    "L8FEL2DL4EFAGGO+L2D"
  463.    "L8CDO-L4A#L8AGAA#L2O+CL4DO-AL8GF"
  464.    "L4DDL2GL4AGL8FEL1F$";
  465.  
  466.    static char *string[] = {
  467.    "Stranger in Paradise",
  468.    "Press any key to stop the music",
  469.    };
  470.  
  471.    /* start the music */
  472.  
  473.    fg_musicb(music,1);
  474.  
  475.    /* clear the screen and display the info window */
  476.  
  477.    fg_mousevis(OFF);
  478.    fg_restore(0,xlimit,menu_bottom,ylimit);
  479.  
  480.    info_window(120,520,60,string,2);
  481.    fg_mousevis(ON);
  482.  
  483.    /* continue until done playing or a key is pressed */
  484.  
  485.    while(fg_playing())
  486.    {
  487.       fg_waitfor(1);
  488.       fg_intkey(&key,&aux);
  489.       if (key+aux > 0)
  490.          fg_hush();
  491.       fg_mousebut(1,&count,&lastx,&lasty);
  492.       if (count > 0)
  493.          fg_hush();
  494.    }
  495.  
  496.    /* restore the screen and return to the menu */
  497.  
  498.    fg_mousevis(OFF);
  499.    fg_restore(0,xlimit,menu_bottom,ylimit);
  500.  
  501.    redraw = TRUE;
  502.    return(OK);
  503. }
  504.  
  505. /**********************************************************************\
  506. *                                                                      *
  507. *  do_sound -- an increasing pitch sound effect                        *
  508. *                                                                      *
  509. \**********************************************************************/
  510.  
  511. do_sound()
  512. {
  513.    register int i;
  514.  
  515.    static char *string[] = {
  516.    "Sound Effects",
  517.    "Creating sound effects with Fastgraph",
  518.    "is quite simple.",
  519.    };
  520.  
  521.    /* clear the screen and display the info window */
  522.  
  523.    fg_mousevis(OFF);
  524.    fg_restore(0,xlimit,menu_bottom,ylimit);
  525.  
  526.    info_window(120,520,60,string,3);
  527.  
  528.    /* make the noise */
  529.  
  530.    for (i = 1000; i < 3000; i+=50)
  531.       fg_sound(i,1);
  532.  
  533.    /* wait for a keystroke or mouse button */
  534.  
  535.    fg_mousevis(ON);
  536.    wait_for_keystroke();
  537.  
  538.    /* restore the screen and return to the menu */
  539.  
  540.    fg_mousevis(OFF);
  541.    fg_restore(0,xlimit,menu_bottom,ylimit);
  542.  
  543.    redraw = TRUE;
  544.    return(OK);
  545. }
  546.